package com.jic.manager.controller.manage.merchant;


import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.Certificate;
import com.jic.manager.service.CertificateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资质证书控制器
 * @author zxl
 */
@Slf4j
@RestController
@RequestMapping("certificate")
public class CertificateController {

    @Autowired
    private CertificateService mCertificateService;

    //查询列表
    @PostMapping(value = "/queryCertificateInfo")
    public RestResult<Certificate> queryInfo(@RequestBody Certificate certificate) {
        Certificate certificateVo  = mCertificateService.queryByPrimaryKey(certificate.getId());
        return RestResult.success(certificateVo);
    }

    //查询列表
    @PostMapping(value = "/queryCertificateList")
    public RestResult<List<Certificate>> queryList(@RequestBody Certificate certificate){
        List<Certificate> certificates = mCertificateService.query(certificate);
        return RestResult.success(certificates);
    }
    //编辑方法
    @PostMapping(value = "/editCertificateInfo")
    public RestResult<String> editMerchantInfo(@RequestBody Certificate certificate){

        try {
            log.debug("editCertificateInfo " + certificate);
            return mCertificateService.editCertificateInfo(certificate);
        }catch (Exception e){
            log.error("Manager editCertificateInfo error：",e);
            return RestResult.error("9999","系统异常，编辑资质证书失败");
        }
    }

    //删除方法
    @PostMapping(value = "/deleteCertificateInfo")
    public RestResult deleteCertificateInfo(@RequestBody Certificate certificate){
        try {
            log.debug("deleteCertificateInfo " + certificate);
            return mCertificateService.deleteCertificateInfo(certificate);
        }catch (Exception e){
            log.error("Manager deleteCertificateInfo error：",e);
            return RestResult.error("9999","系统异常，删除失败");
        }
    }

}
